<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Authenticate CLI</title>
  </head>
  <body>
    <script>
      const params = new URLSearchParams(window.location.search);
      const host = params.get("host");

      fetch(`${host}/api/user/api_key`, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ name: "Trieve CLI", role: 1 }),
        credentials: "include",
      })
        .then((response) => response.json())
        .then((data) => {
          window.location.href = `http://localhost:65535?apiKey=${data.api_key}`;
        })
        .catch((error) => console.error("Error:", error));
    </script>
  </body>
</html>
